package com.zz.inventory.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.utils.DateUtils;
import com.zz.inventory.domain.dto.ReviewScoreDTO;
import com.zz.inventory.domain.dto.StudentScoreQuery;
import com.zz.inventory.domain.dto.StudentWorstScoreDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zz.inventory.mapper.StudentsMapper;
import com.zz.inventory.domain.Students;
import com.zz.inventory.service.IStudentsService;

/**
 * 学生信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@Service
public class StudentsServiceImpl implements IStudentsService 
{
    @Autowired
    private StudentsMapper studentsMapper;

    /**
     * 查询学生信息
     * 
     * @param studentId 学生信息主键
     * @return 学生信息
     */
    @Override
    public Students selectStudentsByStudentId(Long studentId)
    {
        return studentsMapper.selectStudentsByStudentId(studentId);
    }

    /**
     * 查询学生信息列表
     * 
     * @param students 学生信息
     * @return 学生信息
     */
    @Override
    public List<Students> selectStudentsList(Students students)
    {
        return studentsMapper.selectStudentsList(students);
    }

    /**
     * 新增学生信息
     * 
     * @param students 学生信息
     * @return 结果
     */
    @Override
    public int insertStudents(Students students)
    {
        students.setCreateTime(DateUtils.getNowDate());
        return studentsMapper.insertStudents(students);
    }

    /**
     * 修改学生信息
     * 
     * @param
     * @return 结果
     */
    @Override
    public int reviewScore(ReviewScoreDTO dto) {
        // 参数校验
        if (dto.getStudentId() == null || dto.getExamId() == null) {
            throw new IllegalArgumentException("复核参数不完整");
        }
        if (dto.getFinalScore() == null || dto.getFinalScore().compareTo(BigDecimal.ZERO) < 0) {
            throw new IllegalArgumentException("成绩必须大于0");
        }

        return studentsMapper.updateScoreStatus(dto);
    }

    /**
     * 批量删除学生信息
     * 
     * @param studentIds 需要删除的学生信息主键
     * @return 结果
     */
    @Override
    public int deleteStudentsByStudentIds(Long[] studentIds)
    {
        return studentsMapper.deleteStudentsByStudentIds(studentIds);
    }

    /**
     * 删除学生信息信息
     * 
     * @param studentId 学生信息主键
     * @return 结果
     */
    @Override
    public int deleteStudentsByStudentId(Long studentId)
    {
        return studentsMapper.deleteStudentsByStudentId(studentId);
    }

    @Override
    public List<StudentWorstScoreDTO> selectStudentWorstScores() {
        return studentsMapper.selectStudentWorstScores();
    }
    @Override
    public PageInfo<StudentWorstScoreDTO> selectStudentWorstScores(StudentScoreQuery query) {
        // 启用分页
        PageHelper.startPage(query.getPageNum(), query.getPageSize());

        // 执行查询
        List<StudentWorstScoreDTO> list = studentsMapper.selectStudentWorstScores(query);

        // 返回分页结果
        return new PageInfo<>(list);
    }

    @Override
    public void updateFe(String fullName, String fileContent) {
        studentsMapper.updateFe(fullName,fileContent);
    }

}
